package codeForce;

import java.util.ArrayList;
import java.util.Scanner;

public class B_EraseFirstorSecondLetterImprove {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            for(int i=0; i<n; i++){
                int sum=0;
                int tmp=sc.nextInt();
                ArrayList<Character> list=new ArrayList<>();
                String str=sc.next();
                char[] charStr=str.toCharArray();
                for (int j = 0; j < charStr.length; j++) {
                    if(!list.contains(charStr[j])){
                      list.add(charStr[j]);
                      sum+=tmp-j;
                    }
                }
                System.out.println(sum);
            }
        }

}
